import pandas as pd
from sklearn import metrics
import numpy as np

def getday(x):

    tempList = x.split("-")[1] + "—" + x.split("-")[2]
    return tempList


def measurefunc(dataOri,dataModel):
    daylist = []
    for i in range(5,26):
        if i < 10:
            num = str(0) + str(i)
        else:
            num = str(i)
        daylist.append("2017-11-" + num)

    daylist = pd.DataFrame(daylist,columns=["date"])
    dataOri = pd.merge(dataOri,daylist,how = "inner", on = "date")
    dataOri["date"] = dataOri["date"].apply(lambda x:getday(x))

    dataOri = pd.merge(dataOri,dataModel,how = "inner", on = ["date","zonecode"])

    print(dataOri)
    print("MSE:", metrics.mean_squared_error(dataOri["quantity"], dataOri["mean"]))
    print("RMSE:", np.sqrt(metrics.mean_squared_error(dataOri["quantity"], dataOri["mean"])))
    print("hello")


QuantityData = pd.read_csv("Data/QuantityPredict.csv",encoding = "GBK")


QuantityData["day"] = QuantityData["date"].apply(lambda x:getday(x))


QuantityMean = QuantityData.groupby(["zonecode","day"],as_index = False)["quantity"].mean()
QuantityMean.columns = ["zonecode","date","mean"]
print(QuantityMean)
measurefunc(QuantityData,QuantityMean)

# QuantityData.to_csv("Data/QuantityTimeTable.csv",encoding = "GBK")

